using System;
using NUnit.Framework;
using ValidationFramework;

namespace ExampleLibraryCSharp.PropertyValidationManagerExamples
{
    public class GuardExample
	{
		#region Example
		public class Person
		{
			#region Fields

			private readonly PropertyValidationManager propertyValidationManager;

			#endregion

			#region Constructors

			public Person()
			{
				propertyValidationManager = new PropertyValidationManager(this);
			}

			#endregion

			#region Properties

		    private int age;

		    [RequiredIntRule]
			public int Age
		    {
		        get { return age; }
		        set
		        {
                    if (value != age)
                    {
                        propertyValidationManager.ThrowException(value, "Age", null);
                        age = value;
                    }
		        }
		    }

		    #endregion

	}

		[TestFixture]
		public class ExampleUsage
		{
			[Test]
			public void RunIsValid()
			{
				var person = new Person();
				// Works because 10 is valid
				person.Age = 10;

			}



            [Test]
            [ExpectedException(typeof(ArgumentException))]
            public void RunInvalid()
            {
                var person = new Person();
                // Works because 10 is valid
                person.Age = 10;
                // Fails because 0 is invalid
                person.Age = 0;
            }
		}
		#endregion
	}
}